# -*- coding: utf-8 -*-
#-----------------------------------------
# @Time       : 2019/12/16 16:08
# @Author     : dqz 
# @Email      : duanqizhong@dangdang.com
# @File       : get_deploy_parameters.py
# @Software   : PyCharm
#-----------------------------------------

import os
import requests
import sys

BASE_DIR="/ci/env-deploy"

if len(sys.argv) != 3:
    print("python3 get_deploy_parameters.py env app")
    sys.exit(1)
env=sys.argv[1]
app=sys.argv[2]

url=f"10.255.209.109:9999/api/v1/env/app/info/?env={env}&app={app}"
env_app_info=requests.get(url)
if not env_app_info["status"]:
    print("ERROR: env app 部署信息获取失败")
    sys.exit(1)

with open(os.path.join(BASE_DIR,f"tmp/{env}-{app}.sh"),"w") as fw:
    for key,value in env_app_info["data"].items():
        fw.write("{key}={value}\n")

